package com.dating.core.comm;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.nutz.mvc.Mvcs;

import com.dating.base.vo.SystemSetting;


public class FileUploads {

	
	/**
	 * 上传文件
	 * @throws IOException 
	 */
	public static String uploadFile(InputStream inputStream, String fileName) throws IOException{
		FileOutputStream fout = null ;
		File uploadDir = new File(Mvcs.getReq().getSession().getServletContext().getRealPath("") + SystemSetting.SYS_UPLOAD_FILE_DIR);
		if(!uploadDir.exists()){
			uploadDir.mkdir();
		}
		fout = new FileOutputStream(uploadDir.getAbsolutePath() + File.separator + fileName);
		byte[] bytes = new byte[2048];
		while(inputStream.read(bytes) != -1){
			fout.write(bytes);
		}
		inputStream.close();
		fout.flush();
		fout.close();
		return SystemSetting.SYS_UPLOAD_FILE_DIR + fileName;
	}
	
}
